#include "listitem.h"
#include "ui_listitem.h"
#include "commonform.h"
#include <QDebug>

ListItem::ListItem(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ListItem),
    isLike(false)
{
    ui->setupUi(this);
    // 初始化不喜欢
    ui->likeButton->setIcon(QIcon(":/image/noLike.png"));
}

ListItem::~ListItem()
{
    delete ui;
}

void ListItem::enterEvent(QEvent *event)
{
    (void) event;
    this->setStyleSheet("background-color: #efefef");
}

void ListItem::leaveEvent(QEvent *event)
{
    (void) event;
    this->setStyleSheet("");
}

void ListItem::setMusicName(const QString &musicName)
{
    ui->musicNameLabel->setText(musicName);
}

void ListItem::setMusicSinger(const QString &musicSinger)
{
    ui->musicSingerLabel->setText(musicSinger);
}

void ListItem::setMusicAlbum(const QString &musicAlbum)
{
    ui->musicAlbumLabel->setText(musicAlbum);
}

void ListItem::setIsLikeAndIcon(bool isLike)
{
    this->isLike = isLike;
    if(isLike)
        // 点了收藏
        ui->likeButton->setIcon(QIcon(":/image/iLike.png"));
    else
        // 不收藏
        ui->likeButton->setIcon(QIcon(":/image/noLike.png"));
}

void ListItem::on_likeButton_clicked()
{
    // 点击收藏按钮，黑心变红心，红心变黑心
    isLike = !isLike;
    setIsLikeAndIcon(isLike);
    // 发送一个更新界面的信号，三个界面都要更新：喜欢的界面移除或者新添歌曲、其他界面红心黑心转换
    emit musicLikeRefresh(isLike);
}
